package com.demo.test1.service.impl;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class LogServiceByCglib implements MethodInterceptor {

    private Object targetObj;

    public LogServiceByCglib(Object targetObj) {
        this.targetObj = targetObj;
    }

    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println(method.getName()+",开始执行");
        method.invoke(targetObj,objects);
        System.out.println(method.getName()+",执行成功");
        return null;
    }
}
